home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / MM3MCp.sea Folder / Made by Marksman / Sources / mm / mmMenuMM_Demo.cp < prev    next >
Encoding:
Text File  |  1994-01-16  |  7.5 KB  |  260 lines  |  [TEXT/MMCC]

  1. /*  Copyright © 1994 George R. Cossey */
  2. /*  mmMenuMM_Demo                Handle menus
  3.  
  4.     File name:  mmMenuMM_Demo
  5.     Function:  This contains the routines to handle menus.
  6.     History: 1/16/94 Original by George Cossey
  7.  
  8.    */
  9.  
  10. #include "mmCommonMM_Demo.h"    /* Common */
  11. #include "CommonMM_Demo.h"        /* Common */
  12.  
  13.  
  14. /* ======================================================= */
  15. /* ======================================================= */
  16.  
  17. /* Routine: Init */
  18. /* Purpose: Load in the menu lists and initialize the menubar */
  19.  
  20. void CmmMenus::Init()                                /* Initialize the menu bar */
  21. {
  22.  
  23. ClearMenuBar();                                        /* Clear any old menu bars */
  24.  
  25. /* This menu is   */
  26. Menu_Apple = GetMenu(Res_Menu_Apple);    /* Get the menu from the resource file */
  27. InsertMenu(Menu_Apple,0);                        /* Insert this menu into the menu bar */
  28. AddResMenu(Menu_Apple,'DRVR');                /* Add in DAs */
  29.  
  30. /* This menu is  File */
  31. Menu_File = GetMenu(Res_Menu_File);    /* Get the menu from the resource file */
  32. InsertMenu(Menu_File,0);                        /* Insert this menu into the menu bar */
  33.  
  34. /* This menu is  Edit */
  35. Menu_Edit = GetMenu(Res_Menu_Edit);    /* Get the menu from the resource file */
  36. InsertMenu(Menu_Edit,0);                        /* Insert this menu into the menu bar */
  37.  
  38. /* This menu is  Windows */
  39. Menu_Windows = GetMenu(Res_Menu_Windows);    /* Get the menu from the resource file */
  40. InsertMenu(Menu_Windows,0);                        /* Insert this menu into the menu bar */
  41.  
  42.  
  43. this->AddExtraMenus();                                /* Add any extra menu lists */
  44.  
  45. DrawMenuBar();                                        /* Draw the menu bar */
  46. }
  47.  
  48. /* ======================================================= */
  49.  
  50. /* Routine: AddExtraMenus */
  51. /* Purpose: Add in more menus */
  52.  
  53. void CmmMenus::AddExtraMenus()
  54. {
  55. /* Expected to be overridden by the user code */
  56. }
  57.  
  58. /* ======================================================= */
  59.  
  60. /* Routine: EnableTheMenus */
  61. /* Purpose: Enable or disable menus before they are pulled down */
  62.  
  63. void CmmMenus::EnableTheMenus()
  64. {
  65. /* Expected to be overridden by the user code */
  66. }
  67.  
  68. /* ======================================================= */
  69.  
  70. /* Routine: DoMenuApple */
  71. /* Purpose: Handle all menu items in this list */
  72.  
  73. Boolean CmmMenus::DoMenuApple(short theItem)
  74. {
  75. short        DNA;                                /* For opening DAs */
  76. Str255        DAName;                                /* For getting DA name */
  77. GrafPtr        SavePort;                            /* Save current port when opening DAs */
  78. Boolean        HandledTheMenuItem;
  79.  
  80.  
  81. HandledTheMenuItem = true;
  82. switch (theItem)                            /* Handle all commands in this menu list */
  83.     {
  84.     case MItem_About_Demo:                /* For item About Demo… */
  85.         gAbout_Demo->Open();        /* Open this modeless dialog */
  86.         break;
  87.     default:                                /* allow other buttons, trap for debug */
  88.         GetPort(&SavePort);                    /* Save the current port */
  89.         GetItem(Menu_Apple,theItem, DAName);    /* Get the name of the DA selected */
  90.         DNA = OpenDeskAcc(DAName);            /*Open the DA selected */
  91.         SetPort(SavePort);                    /* Restore to the saved port */
  92.         HandledTheMenuItem = false;
  93.         break;                                /* end of otherwise */
  94.     }                                        /* end of switch */
  95. return(HandledTheMenuItem);
  96. }
  97.  
  98. /* ======================================================= */
  99.  
  100. /* Routine: DoMenuFile */
  101. /* Purpose: Handle all menu items in this list */
  102.  
  103. Boolean CmmMenus::DoMenuFile(short theItem)
  104. {
  105. Boolean        HandledTheMenuItem;
  106.  
  107.  
  108. HandledTheMenuItem = true;
  109. switch (theItem)                            /* Handle all commands in this menu list */
  110.     {
  111.     case MItem_New:                /* For item New */
  112.         break;
  113.     case MItem_Open:                /* For item Open… */
  114.         gFiles->Open_The_File();        /* Do file open */
  115.         break;
  116.     case MItem_Close:                /* For item Close */
  117.         break;
  118.     case MItem_Save:                /* For item Save */
  119.         gFiles->Save_The_File();        /* Do file save */
  120.         break;
  121.     case MItem_Save_As:                /* For item Save As… */
  122.         gFiles->Save_The_File();        /* Do file save */
  123.         break;
  124.     case MItem_Revert:                /* For item Revert */
  125.         break;
  126.     case MItem_Page_Setup:                /* For item Page Setup… */
  127.         gPrinting->PageSetup();            /* Do Printing PageSetup */
  128.         break;
  129.     case MItem_Print:                /* For item Print… */
  130.         gPrinting->Print_The_Data();    /* Do Printing */
  131.         break;
  132.     case MItem_Quit:                /* For item Quit */
  133.         doneFlag = true;                    /* Quit */
  134.         break;
  135.     default:                                /* allow other buttons, trap for debug */
  136.         HandledTheMenuItem = false;
  137.         break;                                /* end of otherwise */
  138.     }                                        /* end of switch */
  139. return(HandledTheMenuItem);
  140. }
  141.  
  142. /* ======================================================= */
  143.  
  144. /* Routine: DoMenuEdit */
  145. /* Purpose: Handle all menu items in this list */
  146.  
  147. Boolean CmmMenus::DoMenuEdit(short theItem)
  148. {
  149. Boolean        BoolHolder;                        /* For SystemEdit result */
  150. Boolean        HandledTheMenuItem;
  151.  
  152.  
  153. HandledTheMenuItem = true;
  154. BoolHolder = SystemEdit(theItem - 1);        /* Let the DA do the edit to itself */
  155.  
  156. if (!BoolHolder)                            /* If not a DA then we get it */
  157.     {
  158.  
  159. switch (theItem)                            /* Handle all commands in this menu list */
  160.     {
  161.     case MItem_Undo:                /* For item Undo */
  162.         break;
  163.     case MItem_Cut:                /* For item Cut */
  164.         break;
  165.     case MItem_Copy:                /* For item Copy */
  166.         break;
  167.     case MItem_Paste:                /* For item Paste */
  168.         break;
  169.     case MItem_Clear:                /* For item Clear */
  170.         break;
  171.     case MItem_Select_All:                /* For item Select All */
  172.         break;
  173.     default:                                /* allow other buttons, trap for debug */
  174.         HandledTheMenuItem = false;
  175.         break;                                /* end of otherwise */
  176.     }                                        /* end of switch */
  177.     }
  178. else
  179.     HandledTheMenuItem = false;
  180. return(HandledTheMenuItem);
  181. }
  182.  
  183. /* ======================================================= */
  184.  
  185. /* Routine: DoMenuWindows */
  186. /* Purpose: Handle all menu items in this list */
  187.  
  188. Boolean CmmMenus::DoMenuWindows(short theItem)
  189. {
  190. Boolean        HandledTheMenuItem;
  191.  
  192.  
  193. HandledTheMenuItem = true;
  194. switch (theItem)                            /* Handle all commands in this menu list */
  195.     {
  196.     case MItem_Alert:                /* For item Alert… */
  197.         gMy_Alert->BringUpAlert();    /* Open this alert */
  198.         break;
  199.     case MItem_Modal_Dialog:                /* For item Modal Dialog… */
  200.         gMy_Modal->BringUpDialog();    /* Open this modal dialog */
  201.         break;
  202.     case MItem_Movable_Modal_D:                /* For item Movable Modal Dialog… */
  203.         gMy_Movable_Moda->Open();        /* Open this modeless dialog */
  204.         break;
  205.     case MItem_Modeless_Dialog:                /* For item Modeless Dialog… */
  206.         gMy_Modeless->Open();        /* Open this modeless dialog */
  207.         break;
  208.     case MItem_Window:                /* For item Window… */
  209.         gMy_basic_window->Open();        /* Open this window */
  210.         break;
  211.     case MItem_Floating_window:                /* For item Floating window… */
  212.         gFloating_window->Open();        /* Open this window */
  213.         break;
  214.     default:                                /* allow other buttons, trap for debug */
  215.         HandledTheMenuItem = false;
  216.         break;                                /* end of otherwise */
  217.     }                                        /* end of switch */
  218. return(HandledTheMenuItem);
  219. }
  220.  
  221. /* ======================================================= */
  222.  
  223. /* ======================================================= */
  224.  
  225. /* Routine: HandleMenuSelection */
  226. /* Purpose: Vector off to the appropiate menu list handler */
  227.  
  228. Boolean CmmMenus::HandleMenuSelection(short theMenu,short theItem)
  229. {
  230. Boolean        HandledTheMenu;
  231.  
  232.  
  233. HandledTheMenu = true;
  234. switch (theMenu)                                    /* Do selected menu list */
  235.     {
  236.     case Res_Menu_Apple:
  237.         DoMenuApple(theItem);                    /* Go handle this list,  */
  238.         break;
  239.     case Res_Menu_File:
  240.         DoMenuFile(theItem);                    /* Go handle this list, File */
  241.         break;
  242.     case Res_Menu_Edit:
  243.         DoMenuEdit(theItem);                    /* Go handle this list, Edit */
  244.         break;
  245.     case Res_Menu_Windows:
  246.         DoMenuWindows(theItem);                    /* Go handle this list, Windows */
  247.         break;
  248.  
  249.     default:                                        /* allow other buttons, trap for debug */
  250.         HandledTheMenu = false;
  251.         break;                                        /* end of otherwise */
  252.     }                                                /* end of switch */
  253.  
  254. HiliteMenu(0);                                        /* Turn menu selection off */
  255. return(HandledTheMenu);
  256. }
  257.  
  258. /* ======================================================= */
  259. /* ======================================================= */
  260.